package com.lj.sys.result;

import cn.hutool.core.text.StrPool;
import cn.hutool.core.util.StrUtil;
import com.lj.sys.entity.SysDataScope;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.Data;

import java.util.List;

/**
 * <p>
 * 数据范围表 信息结果
 * </p>
 *
 * @author lj
 * @since 2025-08-06 18:24:15
 */
@Data
@Schema(description = "数据范围表 信息结果")
public class SysDataScopeInfoResult {

    @Schema(description = "主键id ")
    private Long id;

    @Schema(description = "请求的接口路径 ")
    private String urlPath;

    @Schema(description = "目标id(用户id或者角色id) ")
    private Long targetId;

    @Schema(description = "数据范围 参考字典: SysDataScopeType")
    private Integer scope;

    @Schema(description = "自定义范围(部门id多个逗号分隔) ")
    private List<String> custom;

    public static SysDataScopeInfoResult of(SysDataScope entity) {
        if (entity == null) {
            return null;
        }
        SysDataScopeInfoResult result = new SysDataScopeInfoResult();
        result.setId(entity.getId());
        result.setUrlPath(entity.getUrlPath());
        result.setTargetId(entity.getTargetId());
        result.setScope(entity.getScope() != null ? entity.getScope().getValue() : null);
        result.setCustom(StrUtil.split(entity.getCustom(), StrPool.COMMA));
        return result;
    }
}
